﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;

namespace EditorAutoClose
{
   public class Settings
   {
      private const string REG_KEY_NAME = "MaxEditors";
      private const string REG_PATH = @"Software\EditorAutoClose";
      private const int defaultMax = 10;

      public static int MaxEditors
      {
         get
         {
            return
               GetMaxEditors();
         }
         set
         {
            SetMaxEditors(value);
         }
      }

      private static int GetMaxEditors()
      {
         int m = defaultMax;
         RegistryKey reg = Registry.CurrentUser.OpenSubKey(REG_PATH);
         if (reg == null)
         {
            reg = Registry.CurrentUser.CreateSubKey(REG_PATH);
         }

         m = (int)reg.GetValue(REG_KEY_NAME, defaultMax);
         reg.Close();

         return m;
      }

      private static void SetMaxEditors(int m)
      {
         RegistryKey reg = Registry.CurrentUser.OpenSubKey(REG_PATH, true);
         if (reg == null)
         {
            reg = Registry.CurrentUser.CreateSubKey(REG_PATH);
         }

         reg.SetValue(REG_KEY_NAME, m, RegistryValueKind.DWord);
         reg.Close();
      }
   }
}
